<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .success {
            color: green
        }

        .error {
            color: red
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            用户名 <input v-model="username" />
            <span :class="usernameclass">{{usernametip}}</span>
        </div>
        <div>
            密码 <input v-model="userpwd" />
            <span :class="userpwdclass">
                {{userpwdtip}}
            </span>
        </div>
        <div>
            手机号 <input v-model="usertel" />
        </div>
    </div>

</body>
<script>
    new Vue({
        el: "#app",
        data: {
            username: "",
            usernamereg: /^[a-z_$][0-9a-z_$]{5,9}$/i,
            usernametip: "请输出数字字母_$组成并且不能以数字开头长度6到10位",
            usernameclass: "error",

            userpwd: "",
            userpwdreg: /^[0-9a-z]{6,10}$/i,
            userpwdtip: "密码数字字母组成长度6到10位",
            userpwdclass: "error",

            usertel: ""

        },
        watch: {
            username() {
                if (this.usernamereg.test(this.username)) {
                    this.usernametip = "√";
                    this.usernameclass = "success";
                } else {
                    this.usernametip = "请输出数字字母_$组成并且不能以数字开头长度6到10位";
                    this.usernameclass = "error";
                }
            },
            userpwd() {
                if (this.userpwdreg.test(this.userpwd)) {
                    this.userpwdtip = "√";
                    this.userpwdclass = "success";
                } else {
                    this.userpwdtip = "密码数字字母组成长度6到10位";
                    this.userpwdclass = "error";
                }
            }
        }
    })


</script>

</html>